use crate::{
    config::{HTML_DIR, WEB_LISTEN_ADDR},
    error::AppErr,
};
use actix_web::{App, HttpServer};

mod api;
mod req;
mod res;
mod utils;

pub async fn run() -> Result<(), AppErr> {

    log::info!("server run:{}", WEB_LISTEN_ADDR);

    let app = || {
        let fs = actix_files::Files::new("/web", HTML_DIR)
            .index_file("index.html");

        App::new()
            .service(fs)
            .configure(api::register)
    };

    HttpServer::new(app).bind(WEB_LISTEN_ADDR)?.run().await?;

    Ok(())
}
